<?php

// $Id$
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
/**
 * Function used to display an horizontal menu inside the admin panel
 *
 * Enable webmasters to navigate thru the module's features.
 * Each time you select an option in the admin panel of the news module, this option is highlighted in this menu
 *
 * @package News
 * @author - stolen to the Newbb team ;-)
 * @copyright	(c) The Xoops Project - www.xoops.org
*/

include '../xoops_version.php';

function adminmenu($currentoption = 0, $breadcrumb = '')
{
global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
$myts =& MyTextSanitizer::getInstance();
	
	/* Nice buttons styles */
	echo "
    	<style type='text/css'>
    	#buttontop { float:left; width:100%; background: #e7e7e7; font-size:93%; line-height:normal; border-top: 1px solid black; border-left: 0px solid black; border-right: 0px solid black; margin: 0; }
    	#buttonbar { float:left; width:100%; background: #e7e7e7 url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/bg.png') repeat-x left bottom; font-size:93%; line-height:normal; border-left: 0px solid black; border-right: 0px solid black; margin-bottom: 0px; }
    	#buttonbar ul { margin:0; margin-top: 15px; padding:10px 10px 0; list-style:none; }
		#buttonbar li { display:inline; margin:0; padding:0; }
		#buttonbar a { float:left; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/left_both.png') no-repeat left top; margin:0; padding:0 0 0 9px; border-bottom:1px solid #000; text-decoration:none; }
		#buttonbar a span { float:left; display:block; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/right_both.png') no-repeat right top; padding:5px 15px 4px 6px; font-weight:bold; color:#765; }
		/* Commented Backslash Hack hides rule from IE5-Mac \*/
		#buttonbar a span {float:none;}
		/* End IE5-Mac hack */
		#buttonbar a:hover span { color:#333; }
		#buttonbar #current a { background-position:0 -150px; border-width:0; }
		#buttonbar #current a span { background-position:100% -150px; padding-bottom:5px; color:#333; }
		#buttonbar a:hover { background-position:0% -150px; }
		#buttonbar a:hover span { background-position:100% -150px; }
		</style>";

	$tblColors = array();
	$tblColors = array_pad ($tblColors, count($adminmenu), ""); 
	
	if($currentoption>=0) {
		$tblColors[$currentoption] = 'current';
	}
	echo "<div id='buttontop' style='border-right: 1px solid black;border-left: 1px solid black;margin-bottom:8px;padding-bottom:0;'>"; 
	echo "<table style='width: 100%; padding:0;' cellspacing='0'><tr>";
	echo "<td style=\"width: 60%; font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;\">"; if(isset($modversion['config'])){echo"<a class=\"nobutton\" href=\"../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=".$xoopsModule->getVar('mid')."\">Preferences</a> | ";} echo"<a href=\"../index.php\">Go to module</a>"; if(isset($modversion['help'])){echo"| <a href=\"".$modversion['helpUrl']."\">Help</a>";} echo "</td>";
	echo "<td style=\"width: 40%; font-size: 10px; text-align: right; color: #2F5376; padding: 0 6px; line-height: 18px;\"><b>" . $xoopsModule->name() . "  </b> " . $breadcrumb . "</td>";
	echo "</tr></table>";
	echo "<div id='buttonbar'>";
	echo "<ul>";
	for($i=0; $i<count($adminmenu); ++$i){ //XOOPS_ROOT_PATH."/modules/".$modversion['dirname']."/admin/
		echo "<li id='" . $tblColors[$i] . "'><a href='".XOOPS_URL."/modules/".$modversion['dirname']."/".$adminmenu[$i]['link']."'><span>" . $adminmenu[$i]['title'] . "</span></a></li>\n";
	}
	echo "</ul></div>";
	echo "</div><div style='margin-bottom:2px;'>&nbsp;</div>";
	
}


function news_collapsableBar($tablename = '', $iconname = '')
{

    ?>
	<script type="text/javascript"><!--
	function goto_URL(object)
	{
		window.location.href = object.options[object.selectedIndex].value;
	}

	function toggle(id)
	{
		if (document.getElementById) { obj = document.getElementById(id); }
		if (document.all) { obj = document.all[id]; }
		if (document.layers) { obj = document.layers[id]; }
		if (obj) {
			if (obj.style.display == "none") {
				obj.style.display = "";
			} else {
				obj.style.display = "none";
			}
		}
		return false;
	}

	var iconClose = new Image();
	iconClose.src = '../images/close12.gif';
	var iconOpen = new Image();
	iconOpen.src = '../images/open12.gif';

	function toggleIcon ( iconName )
	{
		if ( document.images[iconName].src == window.iconOpen.src ) {
			document.images[iconName].src = window.iconClose.src;
		} else if ( document.images[iconName].src == window.iconClose.src ) {
			document.images[iconName].src = window.iconOpen.src;
		}
		return;
	}

	//-->
	</script>
	<?php
	echo "<h4 style=\"color: #2F5376; margin: 6px 0 0 0; \"><a href='#' onClick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "');\">";
}


//##############################
//DISPLAY STATION INFO SECTION
//##############################
function config(){
global $xoopsDB, $xoopsConfig, $xoopsModule;
include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
$form = new XoopsThemeForm('Configuration', 'config', '../admin/admin_formaction.php', 'POST');

			//Get info from DB
			$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("pledge_station_info")."" ) ;
			if ( $result ) {
				$myrow = $xoopsDB->fetchArray($result);
					$welcome = $myrow['welcome'];
					$stationInfo['stationLetters'] = $myrow['stationLetters'];
					$stationInfo['Billing_Recipient_Name'] = $myrow['Billing_Recipient_Name'];
					$stationInfo['billing_recipient_Email'] = $myrow['billing_recipient_Email'];
					$stationInfo['gpg_encrypt_info_4_billing'] = $myrow['gpg_encrypt_info_4_billing'];
					$stationInfo['Customer_Service_local_number'] = $myrow['Customer_Service_local_number'];
					$stationInfo['Customer_Service_toll_free_number'] = $myrow['Customer_Service_toll_free_number'];
					$stationInfo['Customer_Service_Email'] = $myrow['Customer_Service_Email'];
					$stationInfo['non_billing_recipients'] = $myrow['non_billing_recipients'];
					$stationInfo['gpg_encrypt_info_4_non_billing'] = $myrow['gpg_encrypt_info_4_non_billing'];
					$use_ssl = $myrow['use_ssl'];
			} 

$form->addElement(new XoopsFormDhtmlTextArea('Welcome Message', 'welcome', $welcome, 5, 35), $required = false);


			$form->addElement(new XoopsFormText("Station Letters:",'stationLetters','50', '100', $stationInfo['stationLetters']));
			$form->addElement(new XoopsFormText("Name of Customer Service Person:",'Billing_Recipient_Name','50', '100', $stationInfo['Billing_Recipient_Name']));
			$form->addElement(new XoopsFormText("Email Address Sensitive Billing Info will be sent to:",'billing_recipient_Email','50', '100', $stationInfo['billing_recipient_Email']));

			if($stationInfo['gpg_encrypt_info_4_billing'] == 'true'){
				// Display checkbox, initially checked.
				$checked_value = 'true';
				$checkbox3 = new XoopsFormCheckBox("Use GPG encryption to send info to billing email address<br />(HIGHLY RECOMMENDED!)", 'gpg_encrypt_info_4_billing', $checked_value);
				$checkbox3->addOption($checked_value, "yes");
				$form->addElement($checkbox3);
			}else{
				// Display checkbox, initially unchecked.
				$checked_value = 'true';
				$checkbox3 = new XoopsFormCheckBox("Use GPG encryption to send info to billing email address<br />(HIGHLY RECOMMENDED!)", 'gpg_encrypt_info_4_billing', !$checked_value);
				$checkbox3->addOption($checked_value, "yes");
				$form->addElement($checkbox3);
			}

			$form->addElement(new XoopsFormText("Local Customer Service Phone Number",'Customer_Service_local_number','50', '100', $stationInfo['Customer_Service_local_number']));
			$form->addElement(new XoopsFormText("Toll Free Customer Service Phone Number:",'Customer_Service_toll_free_number','50', '100', $stationInfo['Customer_Service_toll_free_number']));
			$form->addElement(new XoopsFormText("Customer Service Email",'Customer_Service_Email','50', '100', $stationInfo['Customer_Service_Email']));
			$form->addElement(new XoopsFormText("Email Address to Send Non-Sensitive Notification<br />(Excludes Billing Info):",'non_billing_recipients','50', '100', $stationInfo['non_billing_recipients']));
			
			if($stationInfo['gpg_encrypt_info_4_non_billing'] == 'true'){
				// Display checkbox, initially checked.
				$checked_value = 'true';
				$checkbox4 = new XoopsFormCheckBox("Use GPG encryption to send info to non-billing email address<br />(HIGHLY RECOMMENDED!)", 'gpg_encrypt_info_4_non_billing', $checked_value);
				$checkbox4->addOption($checked_value, "yes");
				$form->addElement($checkbox4);
			}else{
				// Display checkbox, initially unchecked.
				$checked_value = 'true';
				$checkbox4 = new XoopsFormCheckBox("Use GPG encryption to send info to non-billing email address<br />(HIGHLY RECOMMENDED!)", 'gpg_encrypt_info_4_non_billing', !$checked_value);
				$checkbox4->addOption($checked_value, "yes");
				$form->addElement($checkbox4);
			}
			
			
			if($use_ssl == 'true'){
				// Display checkbox, initially checked.
				$checked_value = 'true';
				$checkbox1 = new XoopsFormCheckBox("Use SSL (Recomended for security purposes)", 'use_ssl', $checked_value);
				$checkbox1->addOption($checked_value, "yes");
				$form->addElement($checkbox1);
			}else{
				// Display checkbox, initially unchecked.
				$checked_value = 'true';
				$checkbox2 = new XoopsFormCheckBox("Use SSL (Recomended for security purposes)", 'use_ssl', !$checked_value);
				$checkbox2->addOption($checked_value, "yes");
				$form->addElement($checkbox2);
			}
			
			
			$form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
			$form->addElement(new XoopsFormHidden('action', 'station_info'));
			$form->display();
	
}

//##############################
//DISPLAY MANAGE PREMIUMS SECTION	
//##############################
function premiums(){
global $xoopsDB, $xoopsConfig, $xoopsModule, $modversion;



//BEGIN SECTION TO ADD NEW PREMIUMS
			echo"
		    <form action='../admin/admin_formaction.php' method='POST' enctype='multipart/form-data' name='addPremium'>\n
			<table border='1' cellpadding='0' cellspacing='0' width='100%'>\n
				<tr><th>Add New Premium</th></tr>\n
				<tr>\n
				<td class='bg2'>\n
				
				<table width='100%' border='0' cellpadding='4' cellspacing='1'>\n
					<tr nowrap='nowrap'>\n               
						<td class='head'>Title:</td>
						<td class='even'><input type='text' name='title' size='32' maxlength='30' value ='"; if(isset($_SESSION['title'])){echo $_SESSION['title'];} echo "'>\n</td>
					</tr>
					<tr>
						<td class='head'>Image:</td>
						<td class='even'><input type='file' name='uploadimage' id='uploadimage' /><input type='hidden' name='xoops_upload_file[]' id='xoops_upload_file[]' value='uploadimage' />&nbsp; (jpeg 120x120 under 15k, no spaces in file name)</td>
					</TR>
					<tr nowrap='nowrap'>\n               
						<td class='head'>Descritpion:</td>
						<td class='even'><textarea name='description' cols='15' rows='2'>"; if(isset($_SESSION['description'])){echo $_SESSION['description'];} echo "</textarea></td>
					</tr>			
					<tr nowrap='nowrap'>\n               
						<td class='head'>Pledge Level:</td>
						<td class='even'><input type='text' name='pledge_level' size='32' maxlength='32' value ='"; if(isset($_SESSION['pledge_level'])){echo $_SESSION['pledge_level'];} echo"'></td>
					</tr>
					<tr nowrap='nowrap'>\n               
						<td class='head'>Featured Premium:</td>";
						if(isset($_SESSION['featured']) && $_SESSION['featured'] == 'true'){
							echo"<td class='even'><input name='featured' type='checkbox' value='true' checked></td>";
						}else{
							echo"<td class='even'><input name='featured' type='checkbox' value='true'></td>";
						}
					echo"	
					</tr>
					<tr nowrap='nowrap'>\n               
						<td class='head'>&nbsp;<input type='hidden' name='action' value='add_premium' /></td>
						<td class='even'><input type='submit' value='Add New Premium' /></td>
					</tr>
				</table>\n
					
												
				</td></tr>\n
			</table>\n
			</form>\n";






			echo("<script language=\"JavaScript\" type=\"text/javascript\">
			<!--
			function modifyPremium(action,ID){
				if(action == 'edit'){
					document.pledge.action = 'index.php?op=editPremiums&currentID=1&editID='+ID;
					document.pledge.submit();	
				}else{
				
					 if(confirm(\"Are you sure you want to delete this premium: \"+ID+\"?\")){
						document.pledge.action = '../admin/admin_formaction.php?action='+action+'&ID='+ID;
						document.pledge.submit();	
					 }else{
					   return false;	
					 }
				
				}

			}
			//-->
			</script>");		
			
	$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("pledge_premiums")."" ) ;		
	$data=array();
	if ( $result ) {
		while ( $myrow = $xoopsDB->fetchArray($result) ) {
		$data[]=$myrow;
		}
	}
			
	news_collapsableBar('sectionmanager', 'toptopicsmanager');
	echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toptopicsmanager' name='toptopicsmanager' src='" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/close12.gif' alt='' /></a>&nbsp;Current Premiums". ' (' . count($data) . ')'."</h4>";
	echo "<div id='sectionmanager'>
	<!--BEGIN COLLAPSABLE DIV-->
		

    <form name='pledge' id='pledge' action='' method='POST' enctype='multipart/form-data'>\n
    <table border='1' cellpadding='0' cellspacing='0' width='100%'>\n
        <tr><th>&nbsp;</th></tr>\n
        <tr>\n
        <td class='bg2'>\n
		
		
            <table width='100%' border='0' cellpadding='4' cellspacing='1'>\n
			<tr nowrap='nowrap'>\n               
                <td class='head'>ID</td>
				<td class='head'>Title</td>
				<td class='head'>Image</td>
				<td class='head'>Description</td>
				<td class='head'>Pledge Level</td>
				<td class='head'>Featured</td>\n
				<td class='head'>Active</td>\n
				<td class='head'>&nbsp;</td>\n
				<td class='head'>&nbsp;</td>\n
			</tr>";
			//Get info from DB
			setlocale(LC_MONETARY, 'en_US');
			

				for ($x=0; $x < count($data); $x++) {
				
				if($x&1){
					echo"<tr class=\"odd\">";
				}else{
					echo"<tr class=\"even\">";
				}
				echo"
						<td class='even'>".$data[$x]['ID']."</td>\n
						<td class='even' nowrap>".$data[$x]['title']."</td>\n
						<td class='even'><img src='../images/uploads/".$data[$x]['image']."'></td>\n
						<td class='even'>".$data[$x]['description']."</td>\n
						<td class='even'>".money_format('%.0n', $data[$x]['pledge_level'])."</td>\n
						<td class='even'>".$data[$x]['featured']."</td>\n
						<td class='even'>".$data[$x]['active']."</td>\n
						<td class='even'><input type='button' value='edit' onClick=\"modifyPremium('edit','".$data[$x]['ID']."')\" /></td>\n
						<td class='even'><input type='button' value='delete' onClick=\"modifyPremium('delete','".$data[$x]['ID']."')\" /></td>\n
					</TR>";
				}//end while
			
			
			echo"
            </table>\n
        </td></tr>\n
    </table></form>\n
	
			<!--END COLLAPSABLE DIV-->
	</div><p></P>";		

	
	}
	
	
//##############################
//DISPLAY MANAGE PREMIUMS SECTION	
//##############################
function editPremiums(){
global $xoopsDB, $xoopsConfig, $xoopsModule;
$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("pledge_premiums")." WHERE ID = '".$_GET['editID']."'" ) ;
			if ( $result ) {
				$x=0;
				while ( $myrow = $xoopsDB->fetchArray($result) ) {
						$_SESSION['title'] = $myrow['title'];
						$_SESSION['description'] = $myrow['description'];
						$_SESSION['pledge_level'] = $myrow['pledge_level'];
						$_SESSION['featured'] = $myrow['featured'];
						$_SESSION['active'] = $myrow['active'];
					++$x;
				}//end while
			} 
	
			echo"
		    <form action='../admin/admin_formaction.php' method='POST' enctype='multipart/form-data' name='pledge'>\n
			<table border='1' cellpadding='0' cellspacing='0' width='100%'>\n
				<tr><th>Edit Premium</th></tr>\n
				<tr>\n
				<td class='bg2'>\n
				
				<table width='100%' border='0' cellpadding='4' cellspacing='1'>\n
					<tr nowrap='nowrap'>\n               
						<td class='head'>Title:</td>
						<td class='even'><input type='text' name='title' size='32' maxlength='30' value ='".$_SESSION['title']."'>\n</td>
					</tr>
					<tr>
						<td class='head'>New Image (leave blank to keep existing image):</td>
						<td class='even'><input type='file' name='uploadimage' id='uploadimage' /><input type='hidden' name='xoops_upload_file[]' id='xoops_upload_file[]' value='uploadimage' />&nbsp; (jpeg 120x120 under 15k, no spaces in file name)</td>
					</TR>
					<tr nowrap='nowrap'>\n               
						<td class='head'>Descritpion:</td>
						<td class='even'><textarea name='description' cols='15' rows='2'>".$_SESSION['description']."</textarea></td>
					</tr>			
					<tr nowrap='nowrap'>\n               
						<td class='head'>Pledge Level:</td>
						<td class='even'><input type='text' name='pledge_level' size='32' maxlength='32' value ='".$_SESSION['pledge_level']."'> </td>
					</tr>
					<tr nowrap='nowrap'>\n               
						<td class='head'>Featured Premium:</td>";
						if($_SESSION['featured'] == 'true'){
							echo"<td class='even'><input name='featured' type='checkbox' value='true' checked></td>";
						}else{
							echo"<td class='even'><input name='featured' type='checkbox' value='true'></td>";
						}
					echo"	
					</tr>
					<tr nowrap='nowrap'>\n               
						<td class='head'>Active:</td>";
						if($_SESSION['active'] == 'true'){
							echo"<td class='even'><input name='active' type='checkbox' value='true' checked></td>";
						}else{
							echo"<td class='even'><input name='active' type='checkbox' value='true'></td>";
						}
					echo"	
					</tr>					
					<tr nowrap='nowrap'>\n               
						<td class='head'>&nbsp;<input type='hidden' name='action' value='edit_premium' /><input type='hidden' name='ID' value='".$_GET['editID']."' /></td>
						<td class='even'><input type='submit' value='Update Premium' /></td>
					</tr>
				</table>\n
					
												
				</td></tr>\n
			</table>\n
			</form>\n";	
			
			}	
	
	
//##############################
//add new pledge level form 
//##############################
function levels(){
global $xoopsDB, $xoopsConfig, $xoopsModule, $modversion;
if(isset($_GET['level'])){//this is an update
				$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("pledge_levels")." WHERE ID = '".$_GET['level']."'" ) ;
				if ($result) {
					$myrow = $xoopsDB->fetchArray($result);
					$value = $myrow['pledge_level'];
					$description = $myrow['description'];
				}


			}
					if(!isset($value)){
						$value = "";
					}
					if(!isset($description)){
						$description = "";
					}

			print "
		    <form action='../admin/admin_formaction.php' method='POST' enctype='multipart/form-data'>\n
			<table border='1' cellpadding='0' cellspacing='0' width='100%'>\n";
			if(isset($_GET['level']) && $_GET['level']){//this is an update
				echo"<tr><th>Edit Pledge Level</th></tr>\n";
			}else{
				echo"<tr><th>Add New Pledge Level</th></tr>\n";
			}
				
				echo"
				<tr>\n
				<td class='bg2'>\n
				
				
					<table width='100%' border='0' cellpadding='4' cellspacing='1'>\n
					<tr nowrap='nowrap'>\n               
						<td class='head' width=\"150\">New Pledge Level:</td>
						<td class='even'><input type='text' name='pledge_level' size='75' maxlength='32' value ='$".$value."'> </td>\n
					</tr>
					<tr nowrap='nowrap'>\n               
						<td class='head' width=\"150\">Description:</td>
						<td class='even'><input type='text' name='description' size='75' maxlength='75' value ='".$description."'> </td>\n
					</tr>					
					<tr nowrap='nowrap'>\n";
					if(isset($_GET['level']) && $_GET['level']){
						echo"<td class='head'>&nbsp;<input type='hidden' name='update_level' value='".$_GET['level']."' /></td>\n
						<td class='even'><input type='submit' value='Update Pledge Level' /></td>";
					}else{
						echo"<td class='head'>&nbsp;<input type='hidden' name='action' value='add_pledge_level' /></td>\n
						<td class='even'><input type='submit' value='Add New Pledge Level' /></td>";
					}
					echo"	
					</tr>					
					
					
					</table>\n
				</td></tr>\n
			</table></form>\n";		
			
			
			
//section to list out pledge levels
//###################################			
if(!isset($_GET['level'])){//this is an update
	$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("pledge_levels")." ORDER BY pledge_level desc" ) ;
	$data=array();
	if ( $result ) {
		while ( $myrow = $xoopsDB->fetchArray($result) ) {
		$data[]=$myrow;
		}
	}
			
			
			echo("<script language=\"JavaScript\" type=\"text/javascript\">
			<!--
			function deleteLevel(action,ID){
					 if(confirm(\"Are you sure you want to delete this pledge level?\")){
						document.pledge.action = '../admin/admin_formaction.php?action='+action+'&ID='+ID;
						document.pledge.submit();	
					 }else{
					   return false;	
					 } 
			}
			
			function modifyLevel(ID){
			
						document.pledge.action = 'index.php?op=editLevel&currentID=2&level='+ID;
						document.pledge.submit();	
			}			
			
			
			
			//-->
			</script>");					
			
			
	news_collapsableBar('sectionmanager', 'toptopicsmanager');
	echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toptopicsmanager' name='toptopicsmanager' src='" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/close12.gif' alt='' /></a>&nbsp;Current Pledge Levels". ' (' . count($data) . ')'."</h4>";
	echo "<div id='sectionmanager'>
	<!--BEGIN COLLAPSABLE DIV-->			
			

			<form name='pledge' action='' method='POST' enctype='multipart/form-data'>\n
			<table border='1' cellpadding='0' cellspacing='0' width='100%'>\n
				<tr><th>&nbsp;</th></tr>\n
				<tr>\n
				<td class='bg2'>\n
				
				
					<table width='100%' border='0' cellpadding='4' cellspacing='1'>\n
					<tr nowrap='nowrap'>\n               
						<td class='head' width=\"100\">Level:</td>
						<td class='head' >Description:</td>\n
						<td class='head' >&nbsp;</td>\n
						<td class='head' >&nbsp;</td>\n
					</tr>";
					//Get info from DB
					setlocale(LC_MONETARY, 'en_US');
					
						
						for ($x=0; $x < count($data); $x++ ) {
						
						
						if($x&1){
							echo"<tr class=\"odd\">";
						}else{
							echo"<tr class=\"even\">";
						}
						echo"
								<td class='even'>".money_format('%.0n', $data[$x]['pledge_level']) ."</td>\n
								<td class='even'>".$data[$x]['description'] ."</td>\n
								<td class='even'><input type='button' value='edit' onClick=\"modifyLevel('".$data[$x]['ID']."')\" /></td>\n
								<td class='even'><input type='button' value='delete' onClick=\"deleteLevel('delete_pledge_level','".$data[$x]['ID']."')\" /></td>\n
							</TR>";
						}//end while
					
					
					echo"
					</table>\n
				</td></tr>\n
			</table></form>\n			
	<!--END COLLAPSABLE DIV-->
	</div><p></P>";				
	}
		
}



//##############################
//MANAGE Recent pledges
//##############################
function recent(){
global $xoopsDB, $xoopsConfig, $xoopsModule, $modversion;


	include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
	$form = new XoopsThemeForm('Recent Pledges Configuration', 'config', '../admin/admin_formaction.php', 'POST');

			//Get info from DB
			$result = $xoopsDB->query( "SELECT recent_number_2_show, recent_show_date, recent_show_amount FROM ".$xoopsDB->prefix("pledge_station_info")."" ) ;
			if ( $result ) {
				$myrow = $xoopsDB->fetchArray($result);
			} 


			$form->addElement(new XoopsFormText("Number of recent pledges to show:",'recent_number_2_show','2', '2', $myrow['recent_number_2_show']));


			if($myrow['recent_show_date'] == 'true'){
				// Display checkbox, initially checked.
				$checked_value = 'true';
				$checkbox3 = new XoopsFormCheckBox("Display date of recent pledges:", 'recent_show_date', $checked_value);
				$checkbox3->addOption($checked_value, "yes");
				$form->addElement($checkbox3);
			}else{
				// Display checkbox, initially unchecked.
				$checked_value = 'true';
				$checkbox3 = new XoopsFormCheckBox("Display date of recent pledges:", 'recent_show_date', !$checked_value);
				$checkbox3->addOption($checked_value, "yes");
				$form->addElement($checkbox3);
			} 


			if($myrow['recent_show_amount'] == 'true'){
				// Display checkbox, initially checked.
				$checked_value = 'true';
				$checkbox2 = new XoopsFormCheckBox("Display amount of recent pledges:", 'recent_show_amount', $checked_value);
				$checkbox2->addOption($checked_value, "yes");
				$form->addElement($checkbox2);
			}else{
				// Display checkbox, initially unchecked.
				$checked_value = 'true';
				$checkbox2 = new XoopsFormCheckBox("Display amount of recent pledges:", 'recent_show_amount', !$checked_value);
				$checkbox2->addOption($checked_value, "yes");
				$form->addElement($checkbox2);
			} 

	
$form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
$form->addElement(new XoopsFormHidden('action', 'recent'));
$form->display();

$result = $xoopsDB->query( "SELECT ID, name FROM ".$xoopsDB->prefix("pledge_recent")."  ORDER BY date desc" ) ;
			if ( $result ) {
			$data=array();
				while ( $myrow = $xoopsDB->fetchArray($result) ) {
					$data[] = $myrow;
				}
			}

//form to delete old pledges
	news_collapsableBar('sectionmanager', 'toptopicsmanager');
	echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toptopicsmanager' name='toptopicsmanager' src='" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/close12.gif' alt='' /></a>&nbsp;Delete Recent Pledges". ' (' . count($data) . ')'."</h4>";
	echo "<div id='sectionmanager'>
	<!--BEGIN COLLAPSABLE DIV-->	";		

$recent_form = new XoopsThemeForm('&nbsp;', 'recent', '../admin/admin_formaction.php', 'POST');

				
				for ($x=0; $x < count($data); $x++) {
				$ID = $data[$x]['ID'];
				$name = stripslashes($data[$x]['name']);
				
				$checked_value = $ID;
				$checkbox[$x] = new XoopsFormCheckBox("$name", "delete$x", !$checked_value);
				$checkbox[$x]->addOption($checked_value, "delete");
				$recent_form->addElement($checkbox[$x]);
				}//end while


$recent_form->addElement(new XoopsFormButton('', 'update', 'Update', 'submit'));
$recent_form->addElement(new XoopsFormHidden('action', 'recent_delete'));
$recent_form->addElement(new XoopsFormHidden('highnumber', $x));
$recent_form->display();
	echo	"<!--END COLLAPSABLE DIV-->
	</div><p></P>";			

}

?>
